package com.study.spmongodb.wwj.thread2.char14;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/8 22:42
 */
public class CountDown {
    private final int total;

    private int counter;

    public CountDown(int total) {
        this.total = total;
    }


    public void down() {
        synchronized (this) {
            this.counter++;
            this.notifyAll();
        }
    }

    public void await() {
        synchronized (this) {
            while (counter != total) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
